#import "layer_library_treasure.h"

#define TREASURE_FONT_NAME @"ArialMT"
#define TREASURE_FONT_COUNT @"Helvetica-Bold"

#if (HARD_WARE == HARD_WARE_IPHONE)
  #define TREASURE_FONT_SIZE 12
#elif (HARD_WARE == HARD_WARE_IPAD)
  #define TREASURE_FONT_SIZE 24
#endif

#define TREASURE_DESCRIPTION_LINE_OFFSET 5

#define TREASURE_CURRENT_SELECT_TABLE_WEAPON 0
#define TREASURE_CURRENT_SELECT_TABLE_ITEM 1
#define TREASURE_CURRENT_SELECT_TABLE_EXHIBITION 2

#define TREASURE_OBJECT_AUTO_MOVE_TIME 0.2

#define TREASURE_EXHIBITION_TEXT_BASE_Y 1024.0f
#define TREASURE_EXHIBITION_TEXT_LINE_OFFSET 1.0f
#define TREASURE_EXHIBITION_OPEN_TIME 0.2f
#define TREASURE_EXHIBITION_CLOSE_TIME 0.2f

@implementation layer_library_treasure

@synthesize flagTouchLock = flagTouchLock_;
@synthesize flagFunctionLock = flagFunctionLock_;

- (id)initLayerLibraryTreasure
{
	int i, j;
	float _DescriptionTotalY;
	float _DescriptionStartY;
	STreasureWeaponObject _Weapon;
	STreasureItemObject _Item;
	STreasureExhibitionObject _ExhibitionElement;
	CCLabelTTF *_Label;
	CCSprite *_ImageLabelWeapon;
	CCSprite *_ImageLabelItem;
	CCSprite *_ImageLabelExhibition;
	CCSprite *_ImageCover;
	CCSprite *_ImageDetail;
	CCSprite *_ImageDescription;
	CCMenuItemImage *_ItemBack;

	if ((self = [super init]))
	{
		/*load resource
		 */
		reLoadResource(&g_CfgLibraryTreasureResourceTable);

		self.isTouchEnabled = YES;

		flagTouchLock_ = false;
		flagFunctionLock_ = false;
		flagTouchDragSelect_ = false;
		currentActiveItemIndex_ = -1;

		currentActiveWeaponIndex_ = 0;
		currentActiveItemIndex_ = 0;

		/*weapon
		 */
		detailWeaponIcon_ = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgWeaponTable[0].icon_path]];
		[self addChild:detailWeaponIcon_ z:3];
		detailWeaponIcon_.positionInPixels = g_CfgLibraryTreasureDetailPosition;
		for (i = 0; i < g_CfgWeaponTable.size(); i++)
		{
			_Weapon.description.clear();
			_Weapon.id = i;
			_Weapon.holder = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageHolderPath]];
			[self addChild:_Weapon.holder];

			/*name
			 */
			if (g_RecordWeapLock[i])
			{
				_Weapon.name = [CCLabelTTF labelWithString:@"???" fontName:TREASURE_FONT_NAME fontSize:TREASURE_FONT_SIZE];
			}
			else
			{
				_Weapon.name = [CCLabelTTF labelWithString:[NSString stringWithUTF8String:g_CfgWeaponTable[i].name] fontName:TREASURE_FONT_NAME fontSize:TREASURE_FONT_SIZE];
			}
			[self addChild:_Weapon.name];
			_Weapon.name.color = ccBLACK;

			/*icon
			 */
			if (g_RecordWeapLock[i])
			{
				_Weapon.icon = [CCSprite spriteWithSpriteFrameName:@"icon_locked.png"];
			}
			else
			{
				_Weapon.icon = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgWeaponTable[i].icon_path]];
			}
			[self addChild:_Weapon.icon];
			_Weapon.icon.anchorPoint = ccp(1.0f, 0.5f);

			/*description
			 */
			if (!g_RecordWeapLock[i])
			{
				for (j = 0; j < g_CfgWeaponTable.find(i)->second.description.size(); j++)
				{
					_Label = [CCLabelTTF labelWithString:[NSString stringWithUTF8String:g_CfgWeaponTable.find(i)->second.description[j].c_str()] fontName:TREASURE_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.anchorPoint = ccp(0.5f, 1.0f);
					_Label.color = ccBLACK;
					_Weapon.description.push_back(_Label);
				}
				_DescriptionTotalY = _Weapon.description.size() * _Weapon.description[0].contentSizeInPixels.height + (_Weapon.description.size() - 1) * TREASURE_DESCRIPTION_LINE_OFFSET;
				_DescriptionStartY = g_CfgLibraryTreasureDescriptionPosition.y + _DescriptionTotalY / 2.0f;
				for (j = 0; j < _Weapon.description.size(); j++)
				{
					_Weapon.description[j].positionInPixels = ccp(g_CfgLibraryTreasureDescriptionPosition.x, _DescriptionStartY);
					_DescriptionStartY -= _Weapon.description[0].contentSizeInPixels.height + TREASURE_DESCRIPTION_LINE_OFFSET;
				}
			}
			weaponTable_.push_back(_Weapon);
		}

		/*item
		 */
		detailItemIcon_ = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgItemTable[0].icon_path]];
		[self addChild:detailItemIcon_ z:3];
		detailItemIcon_.positionInPixels = g_CfgLibraryTreasureDetailPosition;
		for (i = 0; i < g_CfgItemTable.size(); i++)
		{
			_Item.description.clear();
			_Item.id = i;
			_Item.holder = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageHolderPath]];
			[self addChild:_Item.holder];

			/*name
			 */
			if (g_RecordItemLock[i])
			{
				_Item.name = [CCLabelTTF labelWithString:@"???" fontName:TREASURE_FONT_NAME fontSize:TREASURE_FONT_SIZE];
			}
			else
			{
				_Item.name = [CCLabelTTF labelWithString:[NSString stringWithUTF8String:g_CfgItemTable[i].name] fontName:TREASURE_FONT_NAME fontSize:TREASURE_FONT_SIZE];
			}
			[self addChild:_Item.name];
			_Item.name.color = ccBLACK;

			/*item
			 */
			if (g_RecordItemLock[i])
			{
				_Item.icon = [CCSprite spriteWithSpriteFrameName:@"icon_locked.png"];
				_Item.count = [CCLabelTTF labelWithString:[NSString stringWithFormat:@" ", g_RecordItemCount[i]] fontName:TREASURE_FONT_COUNT fontSize:16];
			}
			else
			{
				_Item.icon = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgItemTable[i].icon_path]];
				_Item.count = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"%d", g_RecordItemCount[i]] fontName:TREASURE_FONT_COUNT fontSize:16];
			}
			[self addChild:_Item.icon];
			[_Item.icon addChild:_Item.count];
			_Item.icon.anchorPoint = ccp(1.0f, 0.5f);
			_Item.count.color = ccBLACK;
			_Item.count.anchorPoint = ccp(1.2f, 0.0f);
			_Item.count.positionInPixels = ccp(_Item.icon.contentSizeInPixels.width, 0.0f);

			/*description
			 */
			if (!g_RecordItemLock[i])
			{
				for (j = 0; j < g_CfgItemTable.find(i)->second.description.size(); j++)
				{
					_Label = [CCLabelTTF labelWithString:[NSString stringWithUTF8String:g_CfgItemTable.find(i)->second.description[j].c_str()] fontName:TREASURE_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.anchorPoint = ccp(0.5f, 1.0f);
					_Label.color = ccBLACK;
					_Item.description.push_back(_Label);
				}
				_DescriptionTotalY = _Item.description.size() * _Item.description[0].contentSizeInPixels.height + (_Item.description.size() - 1) * TREASURE_DESCRIPTION_LINE_OFFSET;
				_DescriptionStartY = g_CfgLibraryTreasureDescriptionPosition.y + _DescriptionTotalY / 2.0f;
				for (j = 0; j < _Item.description.size(); j++)
				{
					_Item.description[j].positionInPixels = ccp(g_CfgLibraryTreasureDescriptionPosition.x, _DescriptionStartY);
					_DescriptionStartY -= _Item.description[0].contentSizeInPixels.height + TREASURE_DESCRIPTION_LINE_OFFSET;
				}
			}
			itemTable_.push_back(_Item);
		}

		/*exhibition
		 */
		detailExhibitionIcon_ = [CCSprite spriteWithSpriteFrameName:TREASURE_ICON_MUSIC_PATH];
		[self addChild:detailExhibitionIcon_ z:3];
		detailExhibitionIcon_.positionInPixels = g_CfgLibraryTreasureDetailPosition;
		for (i = 0; i < g_CfgExhibitionElementTable.size(); i++)
		{
			_ExhibitionElement.description.clear();
			_ExhibitionElement.id = i;
			_ExhibitionElement.holder = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageHolderPath]];
			[self addChild:_ExhibitionElement.holder];

			/*name
			 */
			if (g_RecordExhibitionElementLock[i])
			{
				_ExhibitionElement.name = [CCLabelTTF labelWithString:@"???" fontName:TREASURE_FONT_NAME fontSize:TREASURE_FONT_SIZE];
			}
			else
			{
				_ExhibitionElement.name = [CCLabelTTF labelWithString:[NSString stringWithUTF8String:g_CfgExhibitionElementTable[i].name] fontName:TREASURE_FONT_NAME fontSize:TREASURE_FONT_SIZE];
			}
			[self addChild:_ExhibitionElement.name];
			_ExhibitionElement.name.color = ccBLACK;

			/*icon
			 */
			if (g_RecordExhibitionElementLock[i])
			{
				_ExhibitionElement.icon = [CCSprite spriteWithSpriteFrameName:@"icon_locked.png"];
			}
			else
			{
				switch (g_CfgExhibitionElementTable[i].type)
				{
				case EXHIBITION_ELEMENT_TYPE_MUSIC:
					_ExhibitionElement.icon = [CCSprite spriteWithSpriteFrameName:TREASURE_ICON_MUSIC_PATH]; break;

				case EXHIBITION_ELEMENT_TYPE_TEXT:
					_ExhibitionElement.icon = [CCSprite spriteWithSpriteFrameName:TREASURE_ICON_TEXT_PATH]; break;

				case EXHIBITION_ELEMENT_TYPE_PICTURE:
					_ExhibitionElement.icon = [CCSprite spriteWithSpriteFrameName:TREASURE_ICON_IMAGE_PATH]; break;

				default:
					;
				}
			}
			[self addChild:_ExhibitionElement.icon];
			_ExhibitionElement.icon.anchorPoint = ccp(1.0f, 0.5f);

			/*description
			 */
			if (!g_RecordExhibitionElementLock[i])
			{
				switch (i)
				{
				case 0:
					_Label = [CCLabelTTF labelWithString:@"我爱你" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 1:
					_Label = [CCLabelTTF labelWithString:@"I love you" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 2:
					_Label = [CCLabelTTF labelWithString:@"Je t'aime" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 3:
					_Label = [CCLabelTTF labelWithString:@"Ich liebe dich" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 4:
					_Label = [CCLabelTTF labelWithString:@"私はあなたを愛して" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 5:
					_Label = [CCLabelTTF labelWithString:@"난 널 사랑해" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 6:
					_Label = [CCLabelTTF labelWithString:@"Я люблю тебя" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 7:
					_Label = [CCLabelTTF labelWithString:@"Te amo" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 8:
					_Label = [CCLabelTTF labelWithString:@"The most distant" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.anchorPoint = ccp(0.5f, -0.1f);
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);

					_Label = [CCLabelTTF labelWithString:@"way in the world" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.anchorPoint = ccp(0.5f, 1.1f);
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 9:
					_Label = [CCLabelTTF labelWithString:@"To The Oak" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 10:
					_Label = [CCLabelTTF labelWithString:@"见与不见" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 11:
					_Label = [CCLabelTTF labelWithString:@"When you are old" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 12:
					if (g_FlagChinese)
					{
						_Label = [CCLabelTTF labelWithString:@"精美壁纸" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					}
					else
					{
						_Label = [CCLabelTTF labelWithString:@"Artworks of lovecupid" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					}
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 13:
					if (g_FlagChinese)
					{
						_Label = [CCLabelTTF labelWithString:@"精美壁纸" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					}
					else
					{
						_Label = [CCLabelTTF labelWithString:@"Artworks of lovecupid" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					}
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 14:
					if (g_FlagChinese)
					{
						_Label = [CCLabelTTF labelWithString:@"精美壁纸" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					}
					else
					{
						_Label = [CCLabelTTF labelWithString:@"Artworks of lovecupid" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					}
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				case 15:
					if (g_FlagChinese)
					{
						_Label = [CCLabelTTF labelWithString:@"精美壁纸" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					}
					else
					{
						_Label = [CCLabelTTF labelWithString:@"Artworks of lovecupid" fontName:TREASURE_UTF16_FONT_NAME fontSize:TREASURE_FONT_SIZE];
					}
					[self addChild:_Label z:3];
					_Label.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;
					_Label.color = ccBLACK;
					_ExhibitionElement.description.push_back(_Label);
					break;

				default:
					;
				}
			}
			exhibitionTable_.push_back(_ExhibitionElement);
		}
		exhibitionPreview_ = nil;

		holderH_ = itemTable_[0].holder.contentSizeInPixels.height;

		/*cover
		 */
		_ImageCover = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageCoverPath]];
		[self addChild:_ImageCover z:1];
		_ImageCover.positionInPixels = g_CfgLibraryTreasureCoverPosition;
		selectObjectRect_.center = g_CfgLibraryTreasureCoverPosition;
		selectObjectRect_.size = _ImageCover.contentSizeInPixels;

		/*table
		 */
		imageTableWeapon_ = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageTableSelectPath]];
		[self addChild:imageTableWeapon_ z:5];
		imageTableItem_ = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageTableUnselectPath]];
		[self addChild:imageTableItem_ z:5];
		imageTableExhibition_ = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageTableUnselectPath]];
		[self addChild:imageTableExhibition_ z:5];
		_ImageLabelWeapon = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageLabelWeaopnPath]];
		[self addChild:_ImageLabelWeapon z:5];
		_ImageLabelItem = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageLabelItemPath]];
		[self addChild:_ImageLabelItem z:5];
		_ImageLabelExhibition = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageLabelExhibitionPath]];
		[self addChild:_ImageLabelExhibition z:5];
		imageTableWeapon_.positionInPixels = g_CfgLibraryTreasureItemTableWeaponPosition;
		imageTableItem_.positionInPixels = g_CfgLibraryTreasureItemTableItemPosition;
		imageTableExhibition_.positionInPixels = g_CfgLibraryTreasureItemTableExhibitionPosition;
		_ImageLabelWeapon.positionInPixels = g_CfgLibraryTreasureItemTableWeaponPosition;
		_ImageLabelItem.positionInPixels = g_CfgLibraryTreasureItemTableItemPosition;
		_ImageLabelExhibition.positionInPixels = g_CfgLibraryTreasureItemTableExhibitionPosition;
		tableWeaponRect_.center = g_CfgLibraryTreasureItemTableWeaponPosition;
		tableWeaponRect_.size = imageTableWeapon_.contentSizeInPixels;
		tableItemRect_.center = g_CfgLibraryTreasureItemTableItemPosition;
		tableItemRect_.size = imageTableItem_.contentSizeInPixels;
		tableExhibitionRect_.center = g_CfgLibraryTreasureItemTableExhibitionPosition;
		tableExhibitionRect_.size = imageTableExhibition_.contentSizeInPixels;

		/*detail
		 */
		_ImageDetail = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageDetailBackPath]];
		[self addChild:_ImageDetail z:2];
		imageSelected_ = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageSelectedPath]];
		[self addChild:imageSelected_ z:4];
		_ImageDetail.positionInPixels = g_CfgLibraryTreasureDetailPosition;
		imageSelected_.positionInPixels = g_CfgLibraryTreasureDetailPosition;
		selectDetailRect_.center = g_CfgLibraryTreasureDetailPosition;
		selectDetailRect_.size = _ImageDetail.contentSizeInPixels;

		/*description
		 */
		_ImageDescription = [CCSprite spriteWithSpriteFrameName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageDescirptionBackPath]];
		[self addChild:_ImageDescription z:2];
		_ImageDescription.positionInPixels = g_CfgLibraryTreasureDescriptionPosition;

		/*item back
		 */
		_ItemBack = uiCreateMenuItemImageObject(&g_CfgLibraryTreasureItemBack, self, @selector(CallBackItemBack:));
		uiNodeAddMenu(self, CGPointZero, _ItemBack, nil);

		/*particle
		 */
		particle1_ = [CCParticleSystemQuad particleWithFile:@"library_treasure_pao_pao_particle.plist"];
		[self addChild:particle1_ z:-1];
		particle2_ = [CCParticleSystemQuad particleWithFile:@"library_treasure_pao_pao_particle.plist"];
		[self addChild:particle2_ z:10];

		/*select weapon table
		 */
		[self SelectTableWeapon];
		[self UpdateSelect];
	}
	return self;
}

- (void)dealloc
{
	/*release resource
	 */
	reFreeResource(&g_CfgLibraryTreasureResourceTable);

	[super dealloc];
}

- (void)ccTouchesBegan:(NSSet *)Touch withEvent:(UIEvent *)Event
{
	CGPoint _Point;
	UITouch *_Touch;

	if (flagTouchLock_)
	{
		return;
	}
	_Touch = [Touch anyObject];
	_Point = [[CCDirector sharedDirector] convertToGL:[_Touch locationInView:[_Touch view]]];
	_Point = ConvertPositionToPositionInPixels(_Point);
	if (nil != exhibitionPreview_)
	{
		[exhibitionPreview_ TouchBegan:_Point];
		return;
	}
	start_ = _Point;
	drag_ = start_;
	flagTouchDragSelect_ = false;
	if (uiPointInCenterRect(_Point, selectObjectRect_))
	{
		flagTouchDragSelect_ = true;
	}
}

- (void)ccTouchesMoved:(NSSet *)Touch withEvent:(UIEvent *)Event
{
	CGPoint _Point;
	UITouch *_Touch;

	if (flagTouchLock_)
	{
		return;
	}
	_Touch = [Touch anyObject];
	_Point = [[CCDirector sharedDirector] convertToGL:[_Touch locationInView:[_Touch view]]];
	_Point = ConvertPositionToPositionInPixels(_Point);
	if (nil != exhibitionPreview_)
	{
		[exhibitionPreview_ TouchMoved:_Point];
		return;
	}
	end_ = _Point;
	if (flagTouchDragSelect_)
	{
		[self DragMove:end_.y - drag_.y];
		drag_ = end_;
	}
}

- (void)ccTouchesEnded:(NSSet *)Touch withEvent:(UIEvent *)Event
{
	int i;
	CGPoint _Point;
	UITouch *_Touch;

	if (flagTouchLock_)
	{
		return;
	}
	_Touch = [Touch anyObject];
	_Point = [[CCDirector sharedDirector] convertToGL:[_Touch locationInView:[_Touch view]]];
	_Point = ConvertPositionToPositionInPixels(_Point);
	if (nil != exhibitionPreview_)
	{
		[exhibitionPreview_ TouchEnded:_Point];
		return;
	}
	end_ = _Point;
	if (flagTouchDragSelect_)
	{
		[self DragMoveEnd:end_.y - drag_.y];
	}
	else
	{
		/*click table weapon
		 */
		if (uiPointInCenterRect(start_, tableWeaponRect_) && uiPointInCenterRect(end_, tableWeaponRect_))
		{
			if (TREASURE_CURRENT_SELECT_TABLE_WEAPON != currentSelectTable_)
			{
				[self SelectTableWeapon];
				goto PLAY_EFFECT_;
			}
			else
			{
				return;
			}
		}

		/*click table item
		 */
		if (uiPointInCenterRect(start_, tableItemRect_) && uiPointInCenterRect(end_, tableItemRect_))
		{
			if (TREASURE_CURRENT_SELECT_TABLE_ITEM != currentSelectTable_)
			{
				[self SelectTableItem];
				goto PLAY_EFFECT_;
			}
			else
			{
				return;
			}
		}

		/*click table exhibition
		 */
		if (uiPointInCenterRect(start_, tableExhibitionRect_) && uiPointInCenterRect(end_, tableExhibitionRect_))
		{
			if (TREASURE_CURRENT_SELECT_TABLE_EXHIBITION != currentSelectTable_)
			{
				[self SelectTableExhibition];
				goto PLAY_EFFECT_;
			}
			else
			{
				return;
			}
		}

		/*click detail
		 */
		if (uiPointInCenterRect(_Point, selectDetailRect_))
		{
			switch (currentSelectTable_)
			{
			case TREASURE_CURRENT_SELECT_TABLE_WEAPON:

				/*check lock
				 */
				if (g_RecordWeapLock[weaponTable_[currentActiveWeaponIndex_].id])
				{
					return;
				}
				if (g_RecordWeapSelected == weaponTable_[currentActiveWeaponIndex_].id)
				{
					return;
				}
				g_RecordWeapSelected = weaponTable_[currentActiveWeaponIndex_].id;
				[imageSelected_ runAction:[CCShow action]];
				goto PLAY_EFFECT_;
				break;

			case TREASURE_CURRENT_SELECT_TABLE_ITEM:

				/*check lock
				 */
				if (g_RecordItemLock[itemTable_[currentActiveItemIndex_].id])
				{
					return;
				}

				/*check unselect
				 */
				for (i = 0; i < ITEM_SELECT_MAX_COUNT; i++)
				{
					if (g_RecordItemSelected[i] == itemTable_[currentActiveItemIndex_].id)
					{
						g_RecordItemSelected[i] = -1;
						[imageSelected_ runAction:[CCHide action]];
						goto PLAY_EFFECT_;
						return;
					}
				}

				/*select
				 */
				g_RecordItemSelected[1] = g_RecordItemSelected[0];
				g_RecordItemSelected[0] = itemTable_[currentActiveItemIndex_].id;
				[imageSelected_ runAction:[CCShow action]];
				goto PLAY_EFFECT_;
				break;

			case TREASURE_CURRENT_SELECT_TABLE_EXHIBITION:

				/*check lock
				 */
				if (g_RecordExhibitionElementLock[exhibitionTable_[currentActiveExhibitionIndex_].id])
				{
					return;
				}
				flagFunctionLock_ = true;
				exhibitionPreview_ = [[sprite_library_treasure_exhibition alloc] initLibraryTreasureExhibition:exhibitionTable_[currentActiveExhibitionIndex_].id];
				[self addChild:exhibitionPreview_ z:10];
				[exhibitionPreview_ release];
				exhibitionPreview_.positionInPixels = g_ScrrenCenter;
				goto PLAY_EFFECT_;
				break;

			default:
				return;
			}
		}

		/*click invalid
		 */
		return;

		PLAY_EFFECT_:

		/*effect
		 */
		EffectButton();
	}
}

- (void)DragMove:(float)Offset
{
	int i, _SelectIndex;

	/*check drag move
	 */
	if (Offset > 0)
	{
		switch (currentSelectTable_)
		{
		case TREASURE_CURRENT_SELECT_TABLE_WEAPON:
		{
			if (weaponTable_[weaponTable_.size() - 1].holder.positionInPixels.y == g_CfgLibraryTreasureHolderBasePosition.y)
			{
				return;
			}
			if (weaponTable_[weaponTable_.size() - 1].holder.positionInPixels.y + Offset > g_CfgLibraryTreasureHolderBasePosition.y)
			{
				Offset = g_CfgLibraryTreasureHolderBasePosition.y - weaponTable_[weaponTable_.size() - 1].holder.positionInPixels.y;
			}
		}
			break;

		case TREASURE_CURRENT_SELECT_TABLE_ITEM:
			if (itemTable_[itemTable_.size() - 1].holder.positionInPixels.y == g_CfgLibraryTreasureHolderBasePosition.y)
			{
				return;
			}
			if (itemTable_[itemTable_.size() - 1].holder.positionInPixels.y + Offset > g_CfgLibraryTreasureHolderBasePosition.y)
			{
				Offset = g_CfgLibraryTreasureHolderBasePosition.y - itemTable_[itemTable_.size() - 1].holder.positionInPixels.y;
			}
			break;

		case TREASURE_CURRENT_SELECT_TABLE_EXHIBITION:
			if (exhibitionTable_[exhibitionTable_.size() - 1].holder.positionInPixels.y == g_CfgLibraryTreasureHolderBasePosition.y)
			{
				return;
			}
			if (exhibitionTable_[exhibitionTable_.size() - 1].holder.positionInPixels.y + Offset > g_CfgLibraryTreasureHolderBasePosition.y)
			{
				Offset = g_CfgLibraryTreasureHolderBasePosition.y - exhibitionTable_[exhibitionTable_.size() - 1].holder.positionInPixels.y;
			}
			break;

		default:
			return;
		}
	}
	else if (Offset < 0)
	{
		switch (currentSelectTable_)
		{
		case TREASURE_CURRENT_SELECT_TABLE_WEAPON:
			if (weaponTable_[0].holder.positionInPixels.y == g_CfgLibraryTreasureHolderBasePosition.y)
			{
				return;
			}
			if (weaponTable_[0].holder.positionInPixels.y + Offset < g_CfgLibraryTreasureHolderBasePosition.y)
			{
				Offset = g_CfgLibraryTreasureHolderBasePosition.y - weaponTable_[0].holder.positionInPixels.y;
			}
			break;

		case TREASURE_CURRENT_SELECT_TABLE_ITEM:
			if (itemTable_[0].holder.positionInPixels.y == g_CfgLibraryTreasureHolderBasePosition.y)
			{
				return;
			}
			if (itemTable_[0].holder.positionInPixels.y + Offset < g_CfgLibraryTreasureHolderBasePosition.y)
			{
				Offset = g_CfgLibraryTreasureHolderBasePosition.y - itemTable_[0].holder.positionInPixels.y;
			}
			break;

		case TREASURE_CURRENT_SELECT_TABLE_EXHIBITION:
			if (exhibitionTable_[0].holder.positionInPixels.y == g_CfgLibraryTreasureHolderBasePosition.y)
			{
				return;
			}
			if (exhibitionTable_[0].holder.positionInPixels.y + Offset < g_CfgLibraryTreasureHolderBasePosition.y)
			{
				Offset = g_CfgLibraryTreasureHolderBasePosition.y - exhibitionTable_[0].holder.positionInPixels.y;
			}
			break;

		default:
			return;
		}
	}
	else
	{
		return;
	}

	/*do drag move
	 */
	switch (currentSelectTable_)
	{
	case TREASURE_CURRENT_SELECT_TABLE_WEAPON:
		for (i = 0; i < weaponTable_.size(); i++)
		{
			weaponTable_[i].holder.positionInPixels = ccp(weaponTable_[i].holder.positionInPixels.x, weaponTable_[i].holder.positionInPixels.y + Offset);
			weaponTable_[i].name.positionInPixels = ccp(weaponTable_[i].name.positionInPixels.x, weaponTable_[i].name.positionInPixels.y + Offset);
			weaponTable_[i].icon.positionInPixels = ccp(weaponTable_[i].icon.positionInPixels.x, weaponTable_[i].icon.positionInPixels.y + Offset);
		}
		break;

	case TREASURE_CURRENT_SELECT_TABLE_ITEM:
		for (i = 0; i < itemTable_.size(); i++)
		{
			itemTable_[i].holder.positionInPixels = ccp(itemTable_[i].holder.positionInPixels.x, itemTable_[i].holder.positionInPixels.y + Offset);
			itemTable_[i].name.positionInPixels = ccp(itemTable_[i].name.positionInPixels.x, itemTable_[i].name.positionInPixels.y + Offset);
			itemTable_[i].icon.positionInPixels = ccp(itemTable_[i].icon.positionInPixels.x, itemTable_[i].icon.positionInPixels.y + Offset);
		}
		break;

	case TREASURE_CURRENT_SELECT_TABLE_EXHIBITION:
		for (i = 0; i < exhibitionTable_.size(); i++)
		{
			exhibitionTable_[i].holder.positionInPixels = ccp(exhibitionTable_[i].holder.positionInPixels.x, exhibitionTable_[i].holder.positionInPixels.y + Offset);
			exhibitionTable_[i].name.positionInPixels = ccp(exhibitionTable_[i].name.positionInPixels.x, exhibitionTable_[i].name.positionInPixels.y + Offset);
			exhibitionTable_[i].icon.positionInPixels = ccp(exhibitionTable_[i].icon.positionInPixels.x, exhibitionTable_[i].icon.positionInPixels.y + Offset);
		}
		break;

	default:
		return;
	}

	/*check drag select
	 */
	switch (currentSelectTable_)
	{
	case TREASURE_CURRENT_SELECT_TABLE_WEAPON:
		_SelectIndex = [self GetSelectIndex];
		if (currentActiveWeaponIndex_ != _SelectIndex)
		{
			currentActiveWeaponIndex_ = _SelectIndex;
			[self UpdateSelect];
		}
		break;

	case TREASURE_CURRENT_SELECT_TABLE_ITEM:
		_SelectIndex = [self GetSelectIndex];
		if (currentActiveItemIndex_ != _SelectIndex)
		{
			currentActiveItemIndex_ = _SelectIndex;
			[self UpdateSelect];
		}
		break;

	case TREASURE_CURRENT_SELECT_TABLE_EXHIBITION:
		_SelectIndex = [self GetSelectIndex];
		if (currentActiveExhibitionIndex_ != _SelectIndex)
		{
			currentActiveExhibitionIndex_ = _SelectIndex;
			[self UpdateSelect];
		}
		break;

	default:
		return;
	}
}

- (void)DragMoveEnd:(float)Offset
{
	int i, _SelectIndex;
	float _Offset;

	_SelectIndex = [self GetSelectIndex];
	if (_SelectIndex == -1)
	{
		return;
	}
	switch (currentSelectTable_)
	{
	case TREASURE_CURRENT_SELECT_TABLE_WEAPON:
		currentActiveItemIndex_ = _SelectIndex;
		_Offset = g_CfgLibraryTreasureHolderBasePosition.y - weaponTable_[currentActiveWeaponIndex_].holder.positionInPixels.y;
		[self UpdateSelect];
		if (fabs(_Offset) == 0.0f)
		{
			return;
		}
		break;

	case TREASURE_CURRENT_SELECT_TABLE_ITEM:
		currentActiveItemIndex_ = _SelectIndex;
		_Offset = g_CfgLibraryTreasureHolderBasePosition.y - itemTable_[currentActiveItemIndex_].holder.positionInPixels.y;
		[self UpdateSelect];
		if (fabs(_Offset) == 0.0f)
		{
			return;
		}
		break;

	case TREASURE_CURRENT_SELECT_TABLE_EXHIBITION:
		currentActiveExhibitionIndex_ = _SelectIndex;
		_Offset = g_CfgLibraryTreasureHolderBasePosition.y - exhibitionTable_[currentActiveExhibitionIndex_].holder.positionInPixels.y;
		[self UpdateSelect];
		if (fabs(_Offset) == 0.0f)
		{
			return;
		}
		break;

	default:
		return;
	}
	switch (currentSelectTable_)
	{
	case TREASURE_CURRENT_SELECT_TABLE_WEAPON:
		for (i = 0; i < weaponTable_.size(); i++)
		{
			[weaponTable_[i].holder runAction:[action_move_y_in_pixel actionWithDuration:TREASURE_OBJECT_AUTO_MOVE_TIME position:ccp(weaponTable_[i].holder.positionInPixels.x, weaponTable_[i].holder.positionInPixels.y + _Offset)]];
			[weaponTable_[i].name runAction:[action_move_y_in_pixel actionWithDuration:TREASURE_OBJECT_AUTO_MOVE_TIME position:ccp(weaponTable_[i].name.positionInPixels.x, weaponTable_[i].name.positionInPixels.y + _Offset)]];
			[weaponTable_[i].icon runAction:[action_move_y_in_pixel actionWithDuration:TREASURE_OBJECT_AUTO_MOVE_TIME position:ccp(weaponTable_[i].icon.positionInPixels.x, weaponTable_[i].icon.positionInPixels.y + _Offset)]];
		}
		break;

	case TREASURE_CURRENT_SELECT_TABLE_ITEM:
		for (i = 0; i < itemTable_.size(); i++)
		{
			[itemTable_[i].holder runAction:[action_move_y_in_pixel actionWithDuration:TREASURE_OBJECT_AUTO_MOVE_TIME position:ccp(itemTable_[i].holder.positionInPixels.x, itemTable_[i].holder.positionInPixels.y + _Offset)]];
			[itemTable_[i].name runAction:[action_move_y_in_pixel actionWithDuration:TREASURE_OBJECT_AUTO_MOVE_TIME position:ccp(itemTable_[i].name.positionInPixels.x, itemTable_[i].name.positionInPixels.y + _Offset)]];
			[itemTable_[i].icon runAction:[action_move_y_in_pixel actionWithDuration:TREASURE_OBJECT_AUTO_MOVE_TIME position:ccp(itemTable_[i].icon.positionInPixels.x, itemTable_[i].icon.positionInPixels.y + _Offset)]];
		}
		break;

	case TREASURE_CURRENT_SELECT_TABLE_EXHIBITION:
		for (i = 0; i < exhibitionTable_.size(); i++)
		{
			[exhibitionTable_[i].holder runAction:[action_move_y_in_pixel actionWithDuration:TREASURE_OBJECT_AUTO_MOVE_TIME position:ccp(exhibitionTable_[i].holder.positionInPixels.x, exhibitionTable_[i].holder.positionInPixels.y + _Offset)]];
			[exhibitionTable_[i].name runAction:[action_move_y_in_pixel actionWithDuration:TREASURE_OBJECT_AUTO_MOVE_TIME position:ccp(exhibitionTable_[i].name.positionInPixels.x, exhibitionTable_[i].name.positionInPixels.y + _Offset)]];
			[exhibitionTable_[i].icon runAction:[action_move_y_in_pixel actionWithDuration:TREASURE_OBJECT_AUTO_MOVE_TIME position:ccp(exhibitionTable_[i].icon.positionInPixels.x, exhibitionTable_[i].icon.positionInPixels.y + _Offset)]];
		}
		break;

	default:
		;
	}
}

- (int)GetSelectIndex
{
	int i, _Ret;
	float _Offset;

	_Ret = 0;
	_Offset = holderH_;
	switch (currentSelectTable_)
	{
	case TREASURE_CURRENT_SELECT_TABLE_WEAPON:
		for (i = 0; i < weaponTable_.size(); i++)
		{
			if (fabs(weaponTable_[i].holder.positionInPixels.y - g_CfgLibraryTreasureHolderBasePosition.y) < _Offset)
			{
				_Offset = fabs(weaponTable_[i].holder.positionInPixels.y - g_CfgLibraryTreasureHolderBasePosition.y);
				_Ret = i;
			}
		}
		return _Ret;

	case TREASURE_CURRENT_SELECT_TABLE_ITEM:
		for (i = 0; i < itemTable_.size(); i++)
		{
			if (fabs(itemTable_[i].holder.positionInPixels.y - g_CfgLibraryTreasureHolderBasePosition.y) < _Offset)
			{
				_Offset = fabs(itemTable_[i].holder.positionInPixels.y - g_CfgLibraryTreasureHolderBasePosition.y);
				_Ret = i;
			}
		}
		return _Ret;

	case TREASURE_CURRENT_SELECT_TABLE_EXHIBITION:
		for (i = 0; i < exhibitionTable_.size(); i++)
		{
			if (fabs(exhibitionTable_[i].holder.positionInPixels.y - g_CfgLibraryTreasureHolderBasePosition.y) < _Offset)
			{
				_Offset = fabs(exhibitionTable_[i].holder.positionInPixels.y - g_CfgLibraryTreasureHolderBasePosition.y);
				_Ret = i;
			}
		}
		return _Ret;

	default:
		return -1;
	}
}

- (void)UpdateSelect
{
	int i;

	switch (currentSelectTable_)
	{
	case TREASURE_CURRENT_SELECT_TABLE_WEAPON:
		[imageSelected_ runAction:currentActiveWeaponIndex_ == g_RecordWeapSelected ?[CCShow action]:[CCHide action]];
		if (g_RecordWeapLock[weaponTable_[currentActiveWeaponIndex_].id])
		{
			[detailWeaponIcon_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"icon_locked.png"]];
		}
		else
		{
			[detailWeaponIcon_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithUTF8String:g_CfgWeaponTable[weaponTable_[currentActiveWeaponIndex_].id].icon_path]]];
		}
		[self WeaponUpdateDescription];
		break;

	case TREASURE_CURRENT_SELECT_TABLE_ITEM :
		[imageSelected_ runAction:[CCHide action]];
		if (g_RecordItemLock[itemTable_[currentActiveItemIndex_].id])
		{
			[detailItemIcon_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"icon_locked.png"]];
		}
		else
		{
			for (i = 0; i < ITEM_SELECT_MAX_COUNT; i++)
			{
				if (itemTable_[currentActiveItemIndex_].id == g_RecordItemSelected[i])
				{
					[imageSelected_ runAction:[CCShow action]];
					break;
				}
			}
			[detailItemIcon_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithUTF8String:g_CfgItemTable[currentActiveItemIndex_].icon_path]]];
		}
		[self ItemUpdateDescription];
		break;

	case TREASURE_CURRENT_SELECT_TABLE_EXHIBITION:
		if (g_RecordExhibitionElementLock[exhibitionTable_[currentActiveExhibitionIndex_].id])
		{
			[detailExhibitionIcon_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"icon_locked.png"]];
		}
		else
		{
			switch (g_CfgExhibitionElementTable[exhibitionTable_[currentActiveExhibitionIndex_].id].type)
			{
			case EXHIBITION_ELEMENT_TYPE_MUSIC:
				[detailExhibitionIcon_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:TREASURE_ICON_MUSIC_PATH]]; break;

			case EXHIBITION_ELEMENT_TYPE_TEXT:
				[detailExhibitionIcon_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:TREASURE_ICON_TEXT_PATH]]; break;

			case EXHIBITION_ELEMENT_TYPE_PICTURE:
				[detailExhibitionIcon_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:TREASURE_ICON_IMAGE_PATH]]; break;

			default:
				;
			}
		}
		[self ExhibitionUpdateDescription];
		break;

	default:
		;
	}
}

- (void)SelectTableWeapon
{
	int i;

	currentSelectTable_ = TREASURE_CURRENT_SELECT_TABLE_WEAPON;

	[imageTableWeapon_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageTableSelectPath]]];
	[imageTableItem_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageTableUnselectPath]]];
	[imageTableExhibition_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageTableUnselectPath]]];

	[self TableWeaponVisible:true];
	[self TableItemVisible:false];
	[self TableExhibitionVisible:false];

	/*setup weapon position
	 */
	currentActiveWeaponIndex_ = 0;
	for (i = 0; i < weaponTable_.size(); i++)
	{
		weaponTable_[i].holder.positionInPixels = ccp(g_CfgLibraryTreasureHolderBasePosition.x, g_CfgLibraryTreasureHolderBasePosition.y - i * holderH_);
		weaponTable_[i].name.positionInPixels = ccp((weaponTable_[i].holder.contentSizeInPixels.width - weaponTable_[i].icon.contentSizeInPixels.width) / 2.0f, g_CfgLibraryTreasureHolderBasePosition.y - i * holderH_);
		weaponTable_[i].icon.positionInPixels = ccp(g_CfgLibraryTreasureHolderBasePosition.x + weaponTable_[i].holder.contentSizeInPixels.width / 2.0f, g_CfgLibraryTreasureHolderBasePosition.y - i * holderH_);
	}
	[self UpdateSelect];
}

- (void)SelectTableItem
{
	int i;

	currentSelectTable_ = TREASURE_CURRENT_SELECT_TABLE_ITEM;

	[imageTableWeapon_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageTableUnselectPath]]];
	[imageTableItem_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageTableSelectPath]]];
	[imageTableExhibition_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageTableUnselectPath]]];

	[self TableWeaponVisible:false];
	[self TableItemVisible:true];
	[self TableExhibitionVisible:false];

	/*setup item position
	 */
	currentActiveItemIndex_ = 0;
	for (i = 0; i < itemTable_.size(); i++)
	{
		itemTable_[i].holder.positionInPixels = ccp(g_CfgLibraryTreasureHolderBasePosition.x, g_CfgLibraryTreasureHolderBasePosition.y - i * holderH_);
		itemTable_[i].name.positionInPixels = ccp((itemTable_[i].holder.contentSizeInPixels.width - itemTable_[i].icon.contentSizeInPixels.width) / 2.0f, g_CfgLibraryTreasureHolderBasePosition.y - i * holderH_);
		itemTable_[i].icon.positionInPixels = ccp(g_CfgLibraryTreasureHolderBasePosition.x + itemTable_[i].holder.contentSizeInPixels.width / 2.0f, g_CfgLibraryTreasureHolderBasePosition.y - i * holderH_);
	}
	[self UpdateSelect];
}

- (void)SelectTableExhibition
{
	int i;

	currentSelectTable_ = TREASURE_CURRENT_SELECT_TABLE_EXHIBITION;

	[imageTableWeapon_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageTableUnselectPath]]];
	[imageTableItem_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageTableUnselectPath]]];
	[imageTableExhibition_ setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithUTF8String:g_CfgLibraryTreasureImageTableSelectPath]]];

	[imageSelected_ runAction:[CCHide action]];

	[self TableWeaponVisible:false];
	[self TableItemVisible:false];
	[self TableExhibitionVisible:true];

	/*setup exhibition position
	 */
	currentActiveExhibitionIndex_ = 0;
	for (i = 0; i < exhibitionTable_.size(); i++)
	{
		exhibitionTable_[i].holder.positionInPixels = ccp(g_CfgLibraryTreasureHolderBasePosition.x, g_CfgLibraryTreasureHolderBasePosition.y - i * holderH_);
		exhibitionTable_[i].name.positionInPixels = ccp((exhibitionTable_[i].holder.contentSizeInPixels.width - exhibitionTable_[i].icon.contentSizeInPixels.width) / 2.0f, g_CfgLibraryTreasureHolderBasePosition.y - i * holderH_);
		exhibitionTable_[i].icon.positionInPixels = ccp(g_CfgLibraryTreasureHolderBasePosition.x + exhibitionTable_[i].holder.contentSizeInPixels.width / 2.0f, g_CfgLibraryTreasureHolderBasePosition.y - i * holderH_);
	}
	[self UpdateSelect];
}

- (void)TableWeaponVisible:(bool)flag
{
	int i, j;

	[detailWeaponIcon_ runAction:flag ?[CCShow action]:[CCHide action]];
	for (i = 0; i < weaponTable_.size(); i++)
	{
		[weaponTable_[i].holder runAction:flag ?[CCShow action]:[CCHide action]];
		[weaponTable_[i].name runAction:flag ?[CCShow action]:[CCHide action]];
		[weaponTable_[i].icon runAction:flag ?[CCShow action]:[CCHide action]];
		for (j = 0; j < weaponTable_[i].description.size(); j++)
		{
			[weaponTable_[i].description[j] runAction:flag ?[CCShow action]:[CCHide action]];
		}
	}
}

- (void)TableItemVisible:(bool)flag
{
	int i, j;

	[detailItemIcon_ runAction:flag ?[CCShow action]:[CCHide action]];
	for (i = 0; i < itemTable_.size(); i++)
	{
		[itemTable_[i].holder runAction:flag ?[CCShow action]:[CCHide action]];
		[itemTable_[i].name runAction:flag ?[CCShow action]:[CCHide action]];
		[itemTable_[i].icon runAction:flag ?[CCShow action]:[CCHide action]];
		[itemTable_[i].count runAction:flag ?[CCShow action]:[CCHide action]];
		for (j = 0; j < itemTable_[i].description.size(); j++)
		{
			[itemTable_[i].description[j] runAction:flag ?[CCShow action]:[CCHide action]];
		}
	}
}

- (void)TableExhibitionVisible:(bool)flag
{
	int i, j;

	[detailExhibitionIcon_ runAction:flag ?[CCShow action]:[CCHide action]];
	for (i = 0; i < exhibitionTable_.size(); i++)
	{
		[exhibitionTable_[i].holder runAction:flag ?[CCShow action]:[CCHide action]];
		[exhibitionTable_[i].name runAction:flag ?[CCShow action]:[CCHide action]];
		[exhibitionTable_[i].icon runAction:flag ?[CCShow action]:[CCHide action]];
		for (j = 0; j < exhibitionTable_[i].description.size(); j++)
		{
			[exhibitionTable_[i].description[j] runAction:flag ?[CCShow action]:[CCHide action]];
		}
	}
}

- (void)WeaponUpdateDescription
{
	int i, j;

	for (i = 0; i < weaponTable_.size(); i++)
	{
		for (j = 0; j < weaponTable_[i].description.size(); j++)
		{
			[weaponTable_[i].description[j] runAction:i == currentActiveWeaponIndex_ ?[CCShow action]:[CCHide action]];
		}
	}
}

- (void)ItemUpdateDescription
{
	int i, j;

	for (i = 0; i < itemTable_.size(); i++)
	{
		for (j = 0; j < itemTable_[i].description.size(); j++)
		{
			[itemTable_[i].description[j] runAction:i == currentActiveItemIndex_ ?[CCShow action]:[CCHide action]];
		}
	}
}

- (void)ExhibitionUpdateDescription
{
	int i, j;

	for (i = 0; i < exhibitionTable_.size(); i++)
	{
		for (j = 0; j < exhibitionTable_[i].description.size(); j++)
		{
			[exhibitionTable_[i].description[j] runAction:i == currentActiveExhibitionIndex_ ?[CCShow action]:[CCHide action]];
		}
	}
}

- (void)DestroyExhibitonView
{
	flagFunctionLock_ = false;

	[self removeChild:exhibitionPreview_ cleanup:YES];
	exhibitionPreview_ = nil;
}

- (void)CallBackItemBack:(id)Sender
{
	if (flagFunctionLock_)
	{
		return;
	}

	/*effect
	 */
	EffectButton();

	RecordSave();
	[g_SceneLibrary SetState:SCENE_LIBRARY_STATE_MAIN];
}

@end